﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Web.Mvc;
using Sample.Models;

namespace Sample.Controllers
{
    public class MyControllerFactory : IControllerFactory
    {
        private static readonly IFormsAuthenticationService FormsService
            = new FormsAuthenticationService();
        private static readonly IMembershipService MembershipService
            = new AccountMembershipService();
        private static readonly DefaultControllerFactory factory
            = new DefaultControllerFactory();

        #region IControllerFactory Members

        public IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName)
        {
            IController controller = null;
            if (controllerName == "AccountController")
            {
                controller = new AccountController(
                    FormsService,
                    MembershipService
                    );
            }
            else
            {
                controller = factory.CreateController(requestContext, controllerName);
            }
            return controller;
        }

        public void ReleaseController(IController controller)
        {
            factory.ReleaseController(controller);
        }

        #endregion
    }
}